@extends('develop.layoutEdit')

@section('title')

    <li class="cur">
        <span>订单设置</span>
    </li>

@endsection


@section('css')
    <link rel="stylesheet" type="text/css" href="/static/libs/uploadify/uploadify.css?v=20170509">
    <link rel="stylesheet" href="/postsystem/docroot/css/common.css?v=20170306" type="text/css" media="screen" />
    <style>
        .layer-go-back{
            display:none;
        }
        .uploadify {
            float: left;
            margin-right: 10px;
        }
    </style>
@endsection

@section('content')

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>订单自动审核：</label>
        <div class="col-sm-9">
            <div class="layui-form">
                <input type="radio" name="bill_auto_audit"  value="1" title="是" checked >
                <input type="radio" name="bill_auto_audit"  value="0" title="否" @if( isset($configure['bill_auto_audit']) && $configure['bill_auto_audit'] == 0 ) checked @endif>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>订单在线付款时效：</label>
        <div class="col-sm-9 form-inline">
            <div class="input-group">
                <input type="text" name="bill_pay_time"  class="form-control" style="width: 120px;"  value="{{ $configure['bill_pay_time'] or 0 }}">
                <span class="input-group-btn">
                    <button class="btn btn-default" >小时</button>
                </span>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>闪购订单在线支付时效：</label>
        <div class="col-sm-9 form-inline">
            <div class="input-group">
                <input type="text" name="flash_bill_pay_time"  class="form-control" style="width: 120px;"  value="{{ $configure['flash_bill_pay_time'] or 0 }}">
                <span class="input-group-btn">
                    <button class="btn btn-default" >分钟</button>
                </span>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>秒杀订单在线支付时效：</label>
        <div class="col-sm-9 form-inline">
            <div class="input-group">
                <input type="text" name="seckill_bill_pay_time"  class="form-control" style="width: 120px;"  value="{{ $configure['seckill_bill_pay_time'] or 0 }}">
                <span class="input-group-btn">
                    <button class="btn btn-default" >分钟</button>
                </span>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>预售订单在线支付时效：</label>
        <div class="col-sm-9 form-inline">
            <div class="input-group">
                <input type="text" name="presale_bill_pay_time"  class="form-control" style="width: 120px;"  value="{{ $configure['presale_bill_pay_time'] or 0 }}">
                <span class="input-group-btn">
                    <button class="btn btn-default" >分钟</button>
                </span>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>第三方物流受理订单超时时间：</label>
        <div class="col-sm-9 form-inline">
            <div class="input-group">
                <input type="text" name="bill_third_receive_overtime"  class="form-control" style="width: 120px;"  value="{{ $configure['bill_third_receive_overtime'] or 0 }}">
                <span class="input-group-btn">
                    <button class="btn btn-default" >分钟</button>
                </span>
            </div><br>
            <span class="help-block">备注：达达快递等配送超出设置的时间未受理，则取消第三方物流系统上的订单。值为0表示不限制</span>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>前端货到付款订单取消条件：</label>
        <div class="col-sm-9">
            <div class="layui-form">
                <input type="radio" name="bill_cancel_condition"  value="1" title="待审核订单" checked >
                <input type="radio" name="bill_cancel_condition"  value="2" title="待审核+已确认订单" @if( isset($configure['bill_cancel_condition']) && $configure['bill_cancel_condition'] == 2 ) checked @endif>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>前端款到发货订单取消条件：</label>
        <div class="col-sm-9">
            <div class="layui-form">
                <input type="radio" name="bill_cancel_condition_onlinepay"  value="1"  title="待审核订单" checked >
                <input type="radio" name="bill_cancel_condition_onlinepay"  value="2" title="待审核+已确认订单" @if( isset($configure['bill_cancel_condition_onlinepay']) && $configure['bill_cancel_condition_onlinepay'] == 2 ) checked @endif>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>订单传入ERP频率：</label>
        <div class="col-sm-9 form-inline">
            <div class="input-group">
                <input type="text" name="bill_erp_frequency"  class="form-control" style="width: 120px;"  value="{{ $configure['bill_erp_frequency'] or 0 }}">
                <span class="input-group-btn">
                    <button class="btn btn-default" >分钟</button>
                </span>
            </div>

        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>订单导出时更改订单状态为发货：</label>
        <div class="col-sm-9">
            <div class="layui-form">
                <input type="radio" name="bill_export_to_bill_deliver"  value="1" title="是" @if( isset($configure['bill_export_to_bill_deliver']) && $configure['bill_export_to_bill_deliver'] == 1 ) checked @endif>
                <input type="radio" name="bill_export_to_bill_deliver"  class="bill_export_to_bill_deliver"  value="0" title="否" @if( isset($configure['bill_export_to_bill_deliver']) && $configure['bill_export_to_bill_deliver'] == 0 ) checked @endif>
            </div>
        </div>
    </div>

    <div class="form-group" id="code">
        <label class="col-sm-3 control-label"><span class="red mr5">*</span>订单生码规则：</label>
        <div class="col-sm-9">
            <div class="layui-form">
                <input type="radio" name="bill_create_pickup_code" class="bill_create_pickup_code" id="code_1" title="不生码" lay-filter="check" value="0" @if( isset($configure['bill_create_pickup_code']) && $configure['bill_create_pickup_code'] == 0 ) checked @endif>
                <input type="radio"  class="bill_create_pickup_code bill_create_pickup"  id="code_2" title="按订单生码" name="bill_create_pickup_code" lay-filter="no_check" value="1" @if( !isset($configure['bill_create_pickup_code']) || $configure['bill_create_pickup_code'] == 1 ) checked @endif>
                <input type="radio" name="bill_create_pickup_code" class="bill_create_pickup_code" id="code_3" title="按商品生码" lay-filter="no_check" value="2" @if( isset($configure['bill_create_pickup_code']) && $configure['bill_create_pickup_code'] == 2 ) checked @endif>
            </div>
        </div>
    </div>

    <div class="form-group  deliver_bill_code" @if( isset($configure['bill_create_pickup_code']) && $configure['bill_create_pickup_code'] == 0 ) style="display: none;" @endif>
        <label class="col-sm-3 control-label"><span class="red mr5"></span></label>
        <div class="col-sm-9">
            <div class="layui-form">
                <input type="checkbox" name="deliver_bill_create_code" class="deliver_bill_create_code" title="配送订单" id="deliver_code" value="1" @if( isset($configure['deliver_bill_create_code']) && $configure['deliver_bill_create_code'] == 1 ) checked @endif>
                <input type="checkbox" value="2" checked="checked" title="自提订单" disabled="disabled"/>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>开启配货环节：</label>
        <div class="col-sm-9">
            <div class="layui-form">
                <input type="radio" name="open_allot"  value="1" title="是" checked>
                <input type="radio" name="open_allot"  value="0" title="否" @if( isset($configure['open_allot']) && $configure['open_allot'] == 0 ) checked @endif>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*</span>订单导出选项：</label>
        <div class="col-sm-9">
            <div class="layui-form">
                <input type="checkbox" name="bill_export_option" class="bill_export_option bill_export"  title="订单信息" value="1" @if( isset($configure['bill_export_option']) && in_array( 1,$configure['bill_export_option'] ) ) checked @endif>
                <input type="checkbox" name="bill_export_option" class="bill_export_option"  title="门店信息" value="2" @if( isset($configure['bill_export_option']) && in_array( 2,$configure['bill_export_option'] ) ) checked @endif>
                <input type="checkbox" name="bill_export_option"  class="bill_export_option" title="商品信息" value="3" @if( isset($configure['bill_export_option']) && in_array( 3,$configure['bill_export_option'] ) ) checked @endif>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5"></span>新订单提示语音：</label>
        <div class="col-sm-9">
            <input type="file"  id="upload_audio" style="float: left;"/>
            <button type="button" class="btn btn-default" id="audio" >从音频库选择</button>
            <div id="audio_box" style="margin-top: 5px;">
                @if( isset( $configure['new_bill_audio']) && !empty( $configure['new_bill_audio'] ) )
                    <audio id="player" controls src="{{ $configure['new_bill_audio'] }}"></audio>
                    <a href="javascript: void(0);" class="del_audio">删除</a>
                @endif
            </div>
            <input type="hidden" name="new_bill_audio" id="new_bill_audio"  value="{{ $configure['new_bill_audio'] }}">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"></label>
        <div class="col-sm-9">
            <input type="hidden" name="function_id" id="function_id" value="{{ $function_id or ''}}">
            <input type="button"  value="保存" onclick="func.edit();" class="btn btn-success">
        </div>
    </div>

@endsection

@section('js')
    <script type="text/javascript" src="/static/libs/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript" src="/static/ebsig/jquery.audio.min.js?v=20170831"></script>
    <script>

        layui.use(['form'], function(){
            var form = layui.form();

            form.on('radio(check)', function(data){
                if ( this.checked ) {
                    $('.deliver_bill_code').hide();
                    $('#deliver_code').val('');
                }
            });
            form.on('radio(no_check)', function(data){
                if ( this.checked ) {
                    $('.deliver_bill_code').show();
                }
            });
        });

        //上传音频
        $(window).ready(function(){

            $("input[id='upload_audio']").uploadify({
                buttonText    :  '<div style="text-align: center">上传音频</div>',
                height        : 35,
                swf           : '/static/libs/uploadify/uploadify.swf',
                uploader      : '/external/upload.php?t=audio&group_id=2',
                width         : 120,
                onUploadSuccess: function(file, data) {
                    data = eval('('+data+')');
                    var url = data.url;

                    $('#audio_box').html('<audio id="player" controls src="' + url + '"></audio><a href="javascript: void(0);" class="del_audio">删除</a>').show();
                    $('#new_bill_audio').val(url);
                }
            });

            $("button[id='audio']").ebsigAudio({
                title: '音频',
                multiple: false,
                success: function(photo_data,id) {
                    var url  = photo_data.link;

                    $('#audio_box').html('<audio id="player" controls src="' + url + '"></audio><a href="javascript: void(0);" class="del_audio">删除</a>').show();
                    var url_data = url.replace('<!--{$ebsig_comm.website.domain_name}-->','');
                    $('#new_bill_audio').val(url_data);
                }
            });

        });

        //删除音频
        $(document).on('click', 'a[class="del_audio"]', function() {
            $('#audio_box').html('').hide();
            $('#new_bill_audio').val('');
        });

        var func = {

            //保存
            edit:function(){

                var message_log = '' ;
                var configure = E.getFormValues('edit-form') ;

                //参数判断
                if( E.isEmpty( configure.function_id ) || !E.isInt( configure.function_id ) ) {
                    message_log += '参数错误<br/>' ;
                }
                if( E.isEmpty( configure.bill_pay_time ) ) {
                    message_log += '订单在线付款时效不能为空<br/>' ;
                }
                if( E.isEmpty( configure.flash_bill_pay_time ) ) {
                    message_log += '闪购订单在线支付时效不能为空<br/>' ;
                }
                if( E.isEmpty( configure.seckill_bill_pay_time ) ) {
                    message_log += '秒杀订单在线支付时效不能为空<br/>' ;
                }
                if( E.isEmpty( configure.presale_bill_pay_time ) ) {
                    message_log += '预售订单在线支付时效不能为空<br/>' ;
                }
                if( E.isEmpty( configure.bill_third_receive_overtime ) ) {
                    message_log += '第三方物流受理订单超时时间不能为空<br/>' ;
                }
                if( E.isEmpty( configure.bill_erp_frequency ) ) {
                    message_log += '订单传入ERP频率不能为空<br/>' ;
                }
                if ((configure.bill_create_pickup_code).length == 0) {
                    message_log += '请选择订单生码规则</br>';
                }
                if((configure.bill_export_option).length==0){
                    message_log += '请选择订单导出选项</br>';
                }
                if(!E.isInt(configure.flash_bill_pay_time)){
                    message_log += '闪购订单在线支付时效必须为整数</br>';
                }
                if(!E.isInt(configure.seckill_bill_pay_time)){
                    message_log += '秒杀订单在线支付时效</br>';
                }
                if(!E.isInt(configure.presale_bill_pay_time)){
                    message_log += '预售订单在线支付时效必须为整数</br>';
                }
                if(!E.isInt(configure.bill_third_receive_overtime)){
                    message_log += '第三方物流受理订单超时时间必须为整数</br>';
                }
                if(!E.isInt(configure.bill_pay_time)){
                    message_log += '订单在线付款时效必须为整数</br>';
                }
                if( !E.isInt(configure.bill_erp_frequency) ){
                    message_log += 'ERP频率必须为整数</br>';
                }
                if ( !E.empty(configure.deliver_bill_create_code[0])) {
                    configure.deliver_bill_create_code = configure.deliver_bill_create_code[0]
                }
                if( message_log ) {
                    layer.alert( message_log , { icon:2 });
                    return false ;
                }

                layer.confirm("您确认保存该设置吗？",{icon:3,offset:'50px'}, function ( index ){
                    layer.close( index );
                    E.ajax( {
                        type:'get',
                        url: '/lar/develop/function/store/'+function_id,
                        data: configure,
                        dataType:'json',
                        // 返回值判断
                        success: function ( obj ){

                            if ( obj.code == 200 ) {
                                layer.alert( obj.message , { icon: 1,time : 1500 } ) ;
                            } else {
                                layer.alert( obj.message , { icon: 2 } ) ;
                            }
                        }
                    } ) ;
                });
            }

        };

    </script>
@endsection